package cpre556.project2.eclipsePlugin.support;

import java.util.Vector;

/**
 * Parent class for plug-ins
 */
public class Plugin{
	/**
	 * Saver instance
	 */
	protected Saver saver = null;
	
	/**
	 * Vulnerabilities list
	 */
	protected Vector<Vulnerability> vulnerabilityList;
	
	/**
	 * Settings
	 */
	protected Settings settings = new Settings();
	
	/**
	 * Constructor
	 */
	public Plugin(){
		
	}
	
	/**
	 * Parse program output to gather vulnerabilities
	 * 
	 * This must fill vulnerabilityList upon completion
	 */
	protected void parseFile(){
		// This is program specific
	}
	
	/**
	 * Generate vulnerability XML
	 */
	public void generateXML(){
		parseFile();
		
		VulnerabilitySorter sorter = new VulnerabilitySorter();
		vulnerabilityList = sorter.sortByLineNumber(vulnerabilityList);
		
		SourceReader reader = new SourceReader(saver);
		
		int size = vulnerabilityList.size();
		
		for (int i = 0; i < size; i++){
			int lineNumber = vulnerabilityList.get(i).getLineNumber();
			vulnerabilityList.get(i).setLineOfCode(reader.getLineOfCode(lineNumber));
		}
		
		XMLWriter writer = new XMLWriter(vulnerabilityList, saver);
		writer.writeXML();
	}
	
	/**
	 * Get the vulnerability list
	 * @return
	 */
	public Vector<Vulnerability> generateXMLVector(){
		generateXML();
		return vulnerabilityList;
	}
	
	/**
	 * Get XML output file
	 * @return
	 */
	public String getOutputFile() {
		return saver.getFile();
	}

	/**
	 * Set saver
	 * @param saver
	 */
	public void setSaver(Saver saver) {
		this.saver = saver;
	}

	/**
	 * Get saver
	 * @return
	 */
	public Saver getSaver() {
		return saver;
	}
}
